package com.kang.user.config;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@MapperScan("com.kang.user.mapper")
public class MyBatisPlusConfig {

	@Value("${mybatis-plus.db-type:mysql}")
	private String dbType;

	@Bean
	public MybatisPlusInterceptor plusInterceptor() {
		try {
			MybatisPlusInterceptor mybatisPlusInterceptor = new MybatisPlusInterceptor();
			mybatisPlusInterceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.valueOf(dbType.toUpperCase())));
			return mybatisPlusInterceptor;
		} catch (IllegalArgumentException e) {
			throw new RuntimeException("Invalid database type specified in configuration: " + dbType, e);
		}
	}
}
